import tools from "@/util/tools";

export default function comparison(val, other) {
  const attrs = [
    "brand",
    "spec",
    "material",
    "other",
    "warehouseName",
    "amountTotal",
    "amountAvailable",
    "premium",
    "price"
  ];
  return new Promise(reslove => {
    let res = JSON.parse(JSON.stringify(val));
    res.forEach((item, idx) => {
      for (const key in item) {
        if (
          Object.prototype.hasOwnProperty.call(item, key) &&
          attrs.indexOf(key) !== -1
        ) {
          if (
            tools.notEmpty(other[idx][key]) &&
            item[key] !== other[idx][key]
          ) {
            item["update" + key] = `(修改为${item[key] || "空"})`;
            item[key] = other[idx][key];
          }
        }
      }
    });
    reslove(res);
  });
}
